package com.seculab.common.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.seculab.member.domain.Member;

public class CommonInterceptor extends HandlerInterceptorAdapter {
	private Logger logger = LoggerFactory.getLogger(CommonInterceptor.class);

	@Override
	public boolean preHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler) throws Exception {

		logger.info("interceptor prehandle executed ");
		HttpSession session = request.getSession(false);
		if (session == null) {
			response.sendRedirect("/admin/app/login/login");
			return false;
		}
		
		Member member = (Member)session.getAttribute("member");
		if (member == null) {
			response.sendRedirect("/admin/app/login/login");
			return false;
		}
		
		logger.info("interceptor session is validated ");
		return true;
		
	}
}
